package com.zyd.dao;

import com.zyd.pojo.Enclosure;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;


/**
 * 电子围栏表持久层
 *
 * @Author: caicaicainiaoa
 * @Date: 2019/4/2  11:48
 */
public interface EnclosureDao extends JpaRepository<Enclosure,Integer> ,JpaSpecificationExecutor<Enclosure> {

    @Query("UPDATE Enclosure SET dr=1 WHERE id= ?1")
    @Modifying
    void updateDrById(Integer id);

    Enclosure findTop1ByInsideStationCodesLikeAndDrEquals(String insideStationCodes,Integer dr);

    Enclosure findTop1ByExternalStationCodesLikeAndDrEquals(String externalStationCodes, Integer dr);

    @Query("UPDATE Enclosure SET carCount=carCount+1 WHERE id= ?1 AND dr=0 ")
    @Modifying
    void increaseCarCountById(Integer id);

    @Query("UPDATE Enclosure SET carCount=carCount-1 WHERE id= ?1 AND dr=0 ")
    @Modifying
    void reduceCarCountById(Integer id);

}
